package com.mission.schedule.CommonDialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.mission.schedule.R;
import com.mission.schedule.activity.QcActivity;
import com.mission.schedule.adapter.ChangYongYuAdapter;
import com.mission.schedule.adapter.DaoJiShiTiXingAdapter;
import com.mission.schedule.adapter.utils.CommonAdapter;
import com.mission.schedule.adapter.utils.ViewHolder;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.CYTXBean;
import com.mission.schedule.clock.QueryAlarmData;
import com.mission.schedule.constants.Const;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.cutimage.Log;
import com.mission.schedule.entity.ScheduleTable;
import com.mission.schedule.my160920.picker.TimePicker2;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.LineGridView;
import com.mission.schedule.utils.SharedPrefUtil;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import android.os.Handler;

/**
 * 常用提醒对话框
 * Created by liwei on 2017/4/18.
 */

public class ReminderDialog extends Dialog {


    CallBack callBack;

    private final static String fileName = "cytx.json";

    List<CYTXBean.QcBean> qcBeanList = new ArrayList<>();
    List<CYTXBean.DjsBean> djsBeanList = new ArrayList<>();

    LineGridView daojishi_gv, selectchangyong_gv,tishi_gv;
    LinearLayout top_ll_back;
    TextView qc_zdy, djs_zdy;

    SharedPrefUtil sharedPrefUtil = null;
    Context context;
    WindowManager windowManager;

    String qcStr = "";
    String djsStr = "";

    String[] zddata = {"06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00",
            "16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"};
    String[] bddata = {"06:30","07:30","08:30","09:30","10:30","11:30","12:30","13:30","14:30","15:30",
            "16:30","17:30","18:30","19:30","20:30","21:30","22:30","23:30"};

    public ReminderDialog(final Context context, final int themeResId, final WindowManager windowManager) {
        super(context, themeResId);
        this.context = context;
        this.windowManager = windowManager;

        setCanceledOnTouchOutside(true);

        View view = LayoutInflater.from(context).inflate(R.layout.dialog_changyong,null);
        setContentView(view);

        top_ll_back = (LinearLayout) view.findViewById(R.id.top_ll_back);
        qc_zdy = (TextView) view.findViewById(R.id.qc_zdy);
        djs_zdy = (TextView) view.findViewById(R.id.djs_zdy);

        daojishi_gv = (LineGridView) view.findViewById(R.id.daojishi_gv);
        selectchangyong_gv = (LineGridView) view.findViewById(R.id.selectchangyong_gv);
        tishi_gv = (LineGridView) view.findViewById(R.id.tishi_gv);

        ScrollView sc = (ScrollView)view.findViewById(R.id.sc);
        sc.scrollTo(0,0);

        setAdapter();

        final TextView zdtx = (TextView) view.findViewById(R.id.zdtx);
        final TextView bdtx = (TextView) view.findViewById(R.id.bdtx);
        zdtx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                zdtx.setTextColor(context.getResources().getColor(R.color.title0));
                bdtx.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
                tiXingAdapter = new TiXingAdapter(zddata);
                tishi_gv.setAdapter(tiXingAdapter);
                tiXingAdapter.notifyDataSetChanged();
                isZD = true;
            }
        });
        bdtx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                zdtx.setTextColor(context.getResources().getColor(R.color.gongkai_txt));
                bdtx.setTextColor(context.getResources().getColor(R.color.title0));
                tiXingAdapter = new TiXingAdapter(bddata);
                tishi_gv.setAdapter(tiXingAdapter);
                tiXingAdapter.notifyDataSetChanged();
                isZD = false;
            }
        });

        daojishi_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    CYTXBean.DjsBean bean = (CYTXBean.DjsBean) daojishi_gv.getAdapter().getItem(position);
                    String date = "";
                    if (bean.type == 1) {
                        date = DateUtil.formatDateTime(DateUtil.parseDateTime(DateUtil.formatDateTime(DateUtil
                                .parseDateTime(DateUtil.formatDateTime(new Date()))
                                .getTime() + (int)bean.number * 60 * 1000)));
                    } else if (bean.type == 2) {
                        date = DateUtil.formatDateTime(DateUtil.parseDateTime(DateUtil.formatDateTime(DateUtil
                                .parseDateTime(DateUtil.formatDateTime(new Date()))
                                .getTime() + (int)(bean.number * 60) * 60 * 1000)));
                    }
                    String createtime = DateUtil.formatDateTimeSs(new Date());
                    int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHID, schID + "");

                    String showTime = "";
                    if (bean.type == 1){
                        showTime = (int)bean.number+"";
                    }else if (bean.type == 2){
                        if (String.valueOf(bean.number).split("\\.")[1].equals("5")){
                            showTime = bean.number+"";
                        }else {
                            showTime = (int)bean.number+"";
                        }
                    }

//                    ReminderDetailDialog detailDialog = new ReminderDetailDialog(context, themeResId, windowManager,
//                            DateUtil.formatDate(DateUtil.parseDate(date)), date.substring(11, 16),
//                            bean.timetype,showTime, showTime + bean.timetype + "倒计时提醒");
//                    detailDialog.show();

                    App.getDBcApplication().insertScheduleData(
                            showTime + bean.timetype + "倒计时提醒",
                            DateUtil.formatDate(DateUtil.parseDate(date)),
                            date.substring(11, 16), 1, 0, 1, 0, 0, 0, 0,
                            createtime, "", 0, "", "", 0, "", "", 1, 0, 0,
                            "到点提醒", "g_001", "", 0, 0, 0, "", "", 0, 0,
                            0,0,"","0","0");
                    Toast toast = Toast.makeText(context, "创建成功\n"+showTime + bean.timetype + "后提醒您", Toast.LENGTH_LONG);
                    int textview_id = Resources.getSystem().getIdentifier("message", "id", "android");
                    ((TextView) toast.getView().findViewById(textview_id)).setGravity(Gravity.CENTER);
                    toast.show();
                    callBack.reminderTime(schID);
                    QueryAlarmData.writeAlarm(context);
                    dismiss();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        tishi_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    String data;
                    if (isZD){
                        data = zddata[position];
                    }else {
                        data = bddata[position];
                    }
                    String today = "";
                    String tomorrow = "";
                    String schtime = "";
                    String schdate = "";
                    Calendar calendar = Calendar.getInstance();
                    today = DateUtil.formatDate(calendar.getTime());
                    calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1);
                    tomorrow = DateUtil.formatDate(calendar.getTime());
                    schtime = DateUtil.formatDateTimeHm(DateUtil.parseDateTimeHm(data));
                    if (DateUtil.parseDateTimeHm(schtime).getTime() > DateUtil.parseDateTimeHm(
                                    DateUtil.formatDateTimeHm(new Date())).getTime()) {
                        schdate = today;
                    } else {
                        schdate = tomorrow;
                    }
                    int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHID, schID + "");
                    String content;
                    if (isZD){
                        content = "整点提醒("+zddata[position]+")";
                    }else {
                        content = "半点提醒("+bddata[position]+")";
                    }
                    App.getDBcApplication().insertScheduleData(
                            content, schdate, schtime, 1, 0, 1, 0, 0,
                            0, 0,
                            DateUtil.formatDateTimeSs(new Date()),
                            "", 0, "", "", 0, "", "", 1, 0, 0,
                            "到点提醒", "g_001", "", 0, 0, 0, "", "", 0,
                            0, 0,0,"","0","0");
                    callBack.reminderTime(schID);
                    QueryAlarmData.writeAlarm(context);
                    dismiss();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        selectchangyong_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    CYTXBean.QcBean bean = (CYTXBean.QcBean) selectchangyong_gv
                            .getAdapter().getItem(position);
                    String schdate;
                    Calendar calendar = Calendar.getInstance();
                    String today = DateUtil.formatDate(calendar.getTime());
                    calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1);
                    String tomorrow = DateUtil.formatDate(calendar.getTime());
                    String schtime = DateUtil.formatDateTimeHm(DateUtil.parseDateTimeHm(bean.time));
                    if (DateUtil.parseDateTimeHm(schtime).getTime() >
                            DateUtil.parseDateTimeHm(DateUtil.formatDateTimeHm(new Date())).getTime()) {
                        schdate = today;
                    } else {
                        schdate = tomorrow;
                    }
                    int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.SCHID, schID + "");
                    Date formTime = DateUtil.parseDateTime(schdate + " " + schtime);
                    Date dateToday = DateUtil.parseDateTime(DateUtil.formatDateTime(new Date()));
                    long betweem = (formTime.getTime() - dateToday.getTime()) / 1000;
                    long day = betweem / (24 * 3600);
                    long hour = betweem % (24 * 3600) / 3600;
                    long min = betweem % 3600 / 60;
                    long C;
                    String timeType;
                    if (Math.abs(day) >= 1) {
                        C = Math.abs(day);
                        timeType = "天";
                    } else {
                        if (Math.abs(hour) >= 1) {
                            C = Math.abs(hour);
                            timeType = "小时";
                        } else {
                            timeType = "分钟";
                            C = Math.abs(min);
                        }
                    }
//                    ReminderDetailDialog detailDialog = new ReminderDetailDialog(context, themeResId, windowManager,
//                            schdate, schtime, timeType, C+"", "起床提醒");
//                    detailDialog.show();
                    App.getDBcApplication().insertScheduleData(
                            "起床提醒", schdate, schtime, 1, 0, 1, 0, 0,
                            0, 0,
                            DateUtil.formatDateTimeSs(new Date()),
                            "", 0, "", "", 0, "", "", 1, 0, 0,
                            "起床", "g_202", "", 0, 0, 0, "", "", 0,
                            0, 0,0,"","0","0");
                    Toast toast = Toast.makeText(context, "创建成功\n"+C + timeType + "后提醒您", Toast.LENGTH_LONG);
                    int textview_id = Resources.getSystem().getIdentifier("message", "id", "android");
                    ((TextView) toast.getView().findViewById(textview_id)).setGravity(Gravity.CENTER);
                    toast.show();
                    callBack.reminderTime(schID);
                    QueryAlarmData.writeAlarm(context);
                    dismiss();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    boolean isZD = true;

    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 1:
                    if (msg.arg1 == 2){
                        djsBeanList.get(msg.arg2).setNumber((double)msg.obj);
                        djsBeanList.get(msg.arg2).setType(2);
                        djsBeanList.get(msg.arg2).setTimetype("小时");
                    }else {
                        djsBeanList.get(msg.arg2).setNumber((double)msg.obj);
                        djsBeanList.get(msg.arg2).setType(1);
                        djsBeanList.get(msg.arg2).setTimetype("分钟");
                    }
                    saveDJS();

                    break;

                case 2:

                    addPersonCalender(msg.arg2);
//                    saveQC();
                    break;

            }
        }
    };
    private void addPersonCalender(int position) {
        Dialog dialog = new Dialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.tx_time_dialog, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = ViewGroup.LayoutParams.MATCH_PARENT;

        new alterAddDialogOnClick(dialog, more_pop_menu, position);
    }


    class alterAddDialogOnClick {

        private View view;
        private Dialog dialog;
        TimePicker2 tp_test;
        int position;

        public alterAddDialogOnClick(Dialog dialog, View view, int position) {
            this.dialog = dialog;
            this.view = view;
            this.position = position;
            initview();
            //滚动组布局
            dialog.show();
        }


        private void initview() {
            tp_test = (TimePicker2) view.findViewById(R.id.tp_test1);
            tp_test.setVisibility(View.VISIBLE);

            String[] t = qcBeanList.get(position).getTime().split(":");
            tp_test.setcuitem1(Integer.valueOf(t[0]) - 1);
            tp_test.setcuitem2(Integer.valueOf(t[1]) - 1);

            tp_test.setOnChangeListener(tp_onchanghelistener);

            view.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (TextUtils.isEmpty(newhour)){
                        dialog.dismiss();
                        return;
                    }
                    qcBeanList.get(position).setTime(newhour+":"+newminute);
                    if (Integer.valueOf(newhour) >= 0 && Integer.valueOf(newhour) < 6 ){
                        qcBeanList.get(position).setTimetype("凌晨");
                        qcBeanList.get(position).setType(1);
                    } else if (Integer.valueOf(newhour) >= 6 && Integer.valueOf(newhour) < 9 ){
                        qcBeanList.get(position).setTimetype("早上");
                        qcBeanList.get(position).setType(2);
                    } else if (Integer.valueOf(newhour) >= 9 && Integer.valueOf(newhour) < 12 ){
                        qcBeanList.get(position).setTimetype("上午");
                        qcBeanList.get(position).setType(3);
                    } else if (Integer.valueOf(newhour) >= 12 && Integer.valueOf(newhour) < 18 ){
                        qcBeanList.get(position).setTimetype("下午");
                        qcBeanList.get(position).setType(4);
                    } else if (Integer.valueOf(newhour) >= 18 && Integer.valueOf(newhour) <= 24 ){
                        qcBeanList.get(position).setTimetype("晚上");
                        qcBeanList.get(position).setType(5);
                    }
                    dialog.dismiss();
                    saveQC();
                }
            });
        }
        String newhour = "",newminute = "";
        TimePicker2.OnChangeListener tp_onchanghelistener = new TimePicker2.OnChangeListener() {
            @Override
            public void onChange(String hour, String minute) {
                newhour = hour;
                newminute = minute;
            }
        };
    }
    private void saveDJS() {
        try {
            JSONArray jsonArray = new JSONArray();
            for (int i = 0; i < djsBeanList.size(); i++) {
                JSONObject tmpObj = new JSONObject();
                tmpObj.put("number", djsBeanList.get(i).number);
                tmpObj.put("timetype", djsBeanList.get(i).timetype);
                tmpObj.put("type", djsBeanList.get(i).type);
                jsonArray.put(tmpObj);
            }
            djsStr = "\"djs\":" + jsonArray.toString();
            String json = "{" + qcStr + djsStr + "}";
            sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.CYTXJSON, json);
//            setAdapter();
            daoJiShiTiXingAdapter.notifyDataSetChanged();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private void saveQC(){
        try {
            JSONArray jsonArray = new JSONArray();
            for (int i = 0; i < qcBeanList.size(); i++) {
                JSONObject tmpObj = new JSONObject();
                tmpObj.put("time", qcBeanList.get(i).getTime());
                tmpObj.put("timetype", qcBeanList.get(i).timetype);
                tmpObj.put("type", qcBeanList.get(i).type);
                jsonArray.put(tmpObj);
            }
            qcStr = "\"qc\":" + jsonArray.toString();
            String json = "{" + qcStr +","+ djsStr + "}";
            sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.CYTXJSON, json);
//            setAdapter();
            changYongYuAdapter.notifyDataSetChanged();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        params.width = windowManager.getDefaultDisplay().getWidth();
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
    }

    private void cjson(String json) {
        try {
            if (json.length() > 0) {
                qcBeanList.clear();
                djsBeanList.clear();

                JSONObject jsonObject = new JSONObject(json);
                qcStr = "\"qc\":" + jsonObject.getJSONArray("qc").toString() + ",";
                djsStr = "\"djs\":" + jsonObject.getJSONArray("djs").toString();
                JSONArray qc = jsonObject.getJSONArray("qc");
                JSONArray djs = jsonObject.getJSONArray("djs");
                for (int i = 0; i < qc.length(); i++) {
                    JSONObject jsonObject1 = qc.getJSONObject(i);
                    CYTXBean.QcBean qcBean = new CYTXBean.QcBean();
                    qcBean.setTime(jsonObject1.getString("time"));
                    qcBean.setTimetype(jsonObject1.getString("timetype"));
                    int fallback = 1;
                    if (jsonObject1.getString("timetype").equals("凌晨")) {
                        fallback = 1;
                    } else if (jsonObject1.getString("timetype").equals("早上")) {
                        fallback = 2;
                    } else if (jsonObject1.getString("timetype").equals("上午")) {
                        fallback = 3;
                    } else if (jsonObject1.getString("timetype").equals("下午")) {
                        fallback = 4;
                    } else if (jsonObject1.getString("timetype").equals("晚上")) {
                        fallback = 5;
                    }
                    qcBean.setType(jsonObject1.optInt("type", fallback));
                    qcBeanList.add(qcBean);
                }
                for (int i = 0; i < djs.length(); i++) {
                    JSONObject jsonObject1 = djs.getJSONObject(i);
                    CYTXBean.DjsBean djsBean = new CYTXBean.DjsBean();
                    djsBean.setNumber(jsonObject1.getDouble("number"));
                    djsBean.setTimetype(jsonObject1.getString("timetype"));
                    int fallback = 1;
                    if (jsonObject1.getString("timetype").equals("分钟")) {
                        fallback = 1;
                    } else if (jsonObject1.getString("timetype").equals("小时")) {
                        fallback = 2;
                    } else if (jsonObject1.getString("timetype").equals("天")) {
                        fallback = 3;
                    }
                    djsBean.setType(jsonObject1.optInt("type", fallback));
                    djsBeanList.add(djsBean);
                }
                Comparator<CYTXBean.QcBean> comparator = new Comparator<CYTXBean.QcBean>() {
                    @Override
                    public int compare(CYTXBean.QcBean lhs, CYTXBean.QcBean rhs) {
                        if (lhs.getType() == rhs.getType()) {
                            return lhs.getTime().compareTo(rhs.getTime());
                        } else {
                            return lhs.getType() - rhs.getType();
                        }
                    }
                };
                Collections.sort(qcBeanList, comparator);
                Comparator<CYTXBean.DjsBean> comparator1 = new Comparator<CYTXBean.DjsBean>() {
                    @Override
                    public int compare(CYTXBean.DjsBean lhs, CYTXBean.DjsBean rhs) {
                        if (lhs.getType() == rhs.getType()) {
                            return (int)(lhs.getNumber() * 60) - (int)(rhs.getNumber() * 60);
                        } else {
                            return lhs.getType() - rhs.getType();
                        }
                    }
                };
                Collections.sort(djsBeanList, comparator1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void getJson() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                StringBuilder sb = new StringBuilder();
                try {
                    AssetManager assetManager = context.getAssets();
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(assetManager.open(fileName)));
                    String line;
                    while ((line = bufferedReader.readLine()) != null) {
                        sb.append(line);
                    }
                    String json = sb.toString();
                    sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.CYTXJSON, sb.toString());
                    cjson(json);
                    setAdapter();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
    DaoJiShiTiXingAdapter daoJiShiTiXingAdapter;
    ChangYongYuAdapter changYongYuAdapter;
    TiXingAdapter tiXingAdapter;
    private void setAdapter() {
        DisplayMetrics metric = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(metric);
        sharedPrefUtil = new SharedPrefUtil(context, ShareFile.USERFILE);
        if (sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CYTXJSON, "").equals("")) {
            getJson();
        } else {
            cjson(sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CYTXJSON, ""));
        }

        daoJiShiTiXingAdapter = new DaoJiShiTiXingAdapter(context, djsBeanList,
                R.layout.adapter_daojishi,windowManager,handler);

        changYongYuAdapter = new ChangYongYuAdapter(context,
                qcBeanList, R.layout.adapter_changyongyu, windowManager, handler);

        daojishi_gv.setAdapter(daoJiShiTiXingAdapter);
        selectchangyong_gv.setAdapter(changYongYuAdapter);

        daoJiShiTiXingAdapter.notifyDataSetChanged();
        changYongYuAdapter.notifyDataSetChanged();

        tiXingAdapter = new TiXingAdapter(zddata);
        tishi_gv.setAdapter(tiXingAdapter);
        tiXingAdapter.notifyDataSetChanged();
    }

    public interface CallBack{
        void reminderTime(int schId);
    }

    public CallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }


    class TiXingAdapter extends BaseAdapter{
        String[] data = {};
        public TiXingAdapter( String[] data) {

            this.data = data;
        }
        @Override
        public int getCount() {
            return data.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null){
                holder = new ViewHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.adapter_tixing,null);
                holder.title = (TextView) convertView.findViewById(R.id.title);
                convertView.setTag(holder);
            }else {
                holder = (ViewHolder)convertView.getTag();
            }
            holder.title.setText(data[position]);
            return convertView;
        }

        class ViewHolder{
            TextView title;
        }
    }
}
